

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="原文链接:NGINX宏观手记 前言任何一个工具都有它的灵魂所在,作为一个PHP程序员，我们可能仅仅使用了它的一小部分，这篇文章让你更加了解Nginx，本章大多都是总结、翻译、整理 ，希望你可以知道nginx不仅仅是PHP的附属品，更宏观的认识它的强大。 变量内置变量存放在 ngx_http_core_module 模块中，变量的命名方式和apache 服务器变量是一致的。总而言之，这些变量代表着客">
<meta property="og:type" content="article">
<meta property="og:title" content="【转】NGINX宏观手记">
<meta property="og:url" content="http://example.com/2018/10/30/nginx/NGINX%E5%AE%8F%E8%A7%82%E6%89%8B%E8%AE%B0/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="原文链接:NGINX宏观手记 前言任何一个工具都有它的灵魂所在,作为一个PHP程序员，我们可能仅仅使用了它的一小部分，这篇文章让你更加了解Nginx，本章大多都是总结、翻译、整理 ，希望你可以知道nginx不仅仅是PHP的附属品，更宏观的认识它的强大。 变量内置变量存放在 ngx_http_core_module 模块中，变量的命名方式和apache 服务器变量是一致的。总而言之，这些变量代表着客">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2018-10-30T05:46:01.000Z">
<meta property="article:modified_time" content="2022-02-10T03:13:15.014Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="Nginx">
<meta property="article:tag" content="运维">
<meta name="twitter:card" content="summary_large_image">
  
  
  <title>【转】NGINX宏观手记 - Hexo</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css" />
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hint.css@2/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css" />
  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.8.13","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 6.0.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>LZDF</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="【转】NGINX宏观手记">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2018-10-30 13:46" pubdate>
        2018年10月30日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      5k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      42 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">【转】NGINX宏观手记</h1>
            
            <div class="markdown-body">
              <p>原文链接:<br><a target="_blank" rel="noopener" href="https://segmentfault.com/a/1190000015842717">NGINX宏观手记</a></p>
<h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>任何一个工具都有它的灵魂所在,作为一个PHP程序员，我们可能仅仅使用了它的一小部分，这篇文章让你更加了解Nginx，本章大多都是总结、翻译、整理 ，希望你可以知道nginx不仅仅是PHP的附属品，更宏观的认识它的强大。</p>
<h1 id="变量"><a href="#变量" class="headerlink" title="变量"></a>变量</h1><p>内置变量存放在 <code>ngx_http_core_module</code> 模块中，变量的命名方式和apache 服务器变量是一致的。总而言之，这些变量代表着客户端请求头的内容，例如 <code>$http_user_agent</code>, <code>$http_cookie</code>, 等等。下面是nginx支持的所有内置变量</p>
<table>
<thead>
<tr>
<th>变量名</th>
<th>注释</th>
</tr>
</thead>
<tbody><tr>
<td>$arg_name</td>
<td>请求中的的参数名，即“?”后面的arg_name=arg_value形式的arg_name</td>
</tr>
<tr>
<td>$args</td>
<td>请求中的参数值</td>
</tr>
<tr>
<td>$binary_remote_addr</td>
<td>客户端地址的二进制形式, 固定长度为4个字节</td>
</tr>
<tr>
<td>$body_bytes_sent</td>
<td>传输给客户端的字节数，响应头不计算在内；这个变量和Apache的 mod_log_config 模块中的“%B”参数保持兼容</td>
</tr>
<tr>
<td>$bytes_sent</td>
<td>传输给客户端的字节数 (1.3.8, 1.2.5)</td>
</tr>
<tr>
<td>$connection</td>
<td>TCP连接的序列号 (1.3.8, 1.2.5)</td>
</tr>
<tr>
<td>$connection_requests</td>
<td>TCP连接当前的请求数量 (1.3.8, 1.2.5)</td>
</tr>
<tr>
<td>$content_length</td>
<td>“Content-Length” 请求头字段</td>
</tr>
<tr>
<td>$content_type</td>
<td>“Content-Type” 请求头字段</td>
</tr>
<tr>
<td>$cookie_name</td>
<td>cookie名称</td>
</tr>
<tr>
<td>$document_root</td>
<td>当前请求的文档根目录或别名</td>
</tr>
<tr>
<td>$document_uri</td>
<td>同 $uri</td>
</tr>
<tr>
<td>$host</td>
<td>优先级如下：HTTP请求行的主机名&gt;”HOST”请求头字段&gt;符合请求的服务器名</td>
</tr>
<tr>
<td>$hostname</td>
<td>主机名</td>
</tr>
<tr>
<td>$http_name</td>
<td>匹配任意请求头字段； 变量名中的后半部分“name”可以替换成任意请求头字段，如在配置文件中需要获取http请求头：“Accept-Language”，那么将“－”替换为下划线，大写字母替换为小写，形如：$http_accept_language即可。</td>
</tr>
<tr>
<td>$https</td>
<td>如果开启了SSL安全模式，值为“on”，否则为空字符串。</td>
</tr>
<tr>
<td>$is_args</td>
<td>如果请求中有参数，值为“?”，否则为空字符串。</td>
</tr>
<tr>
<td>$limit_rate</td>
<td>用于设置响应的速度限制，详见 limit_rate。</td>
</tr>
<tr>
<td>$msec</td>
<td>当前的Unix时间戳 (1.3.9, 1.2.6)</td>
</tr>
<tr>
<td>$nginx_version</td>
<td>nginx版本</td>
</tr>
<tr>
<td>$pid</td>
<td>工作进程的PID</td>
</tr>
<tr>
<td>$pipe</td>
<td>如果请求来自管道通信，值为“p”，否则为“.” (1.3.12, 1.2.7)</td>
</tr>
<tr>
<td>$proxy_protocol_addr</td>
<td>获取代理访问服务器的客户端地址，如果是直接访问，该值为空字符串。(1.5.12)</td>
</tr>
<tr>
<td>$proxy_protocol_port</td>
<td>获取代理访问服务器的客户端的端口，如果是直接访问,该值为空字符串(1.11.0)。</td>
</tr>
<tr>
<td>$query_string</td>
<td>同 $args</td>
</tr>
<tr>
<td>$realpath_root</td>
<td>当前请求的文档根目录或别名的真实路径，会将所有符号连接转换为真实路径。</td>
</tr>
<tr>
<td>$remote_addr</td>
<td>客户端地址</td>
</tr>
<tr>
<td>$remote_port</td>
<td>客户端端口</td>
</tr>
<tr>
<td>$remote_user</td>
<td>用于HTTP基础认证服务的用户名</td>
</tr>
<tr>
<td>$request</td>
<td>代表客户端的请求地址</td>
</tr>
<tr>
<td>$request_body</td>
<td>客户端的请求主体,此变量可在location中使用，将请求主体通过proxy_pass, fastcgi_pass, uwsgi_pass, 和 scgi_pass传递给下一级的代理服务器。</td>
</tr>
<tr>
<td>$request_body_file</td>
<td>将客户端请求主体保存在临时文件中。文件处理结束后，此文件需删除。如果需要之一开启此功能，需要设置client_body_in_file_only。如果将次文件传递给后端的代理服务器，需要禁用request body，即设置proxy_pass_request_body off，fastcgi_pass_request_body off, uwsgi_pass_request_body off, or scgi_pass_request_body off 。</td>
</tr>
<tr>
<td>$request_completion</td>
<td>如果请求成功，值为”OK”，如果请求未完成或者请求不是一个范围请求的最后一部分，则为空。</td>
</tr>
<tr>
<td>$request_filename</td>
<td>当前连接请求的文件路径，由root或alias指令与URI请求生成。</td>
</tr>
<tr>
<td>$request_id</td>
<td>16随机字节(十六进制)生成的唯一请求标识符(1.11.0)</td>
</tr>
<tr>
<td>$request_length</td>
<td>请求的长度 (包括请求的地址, http请求头和请求主体) (1.3.12,</td>
</tr>
<tr>
<td>$request_method</td>
<td>HTTP请求方法，通常为“GET”或“POST”</td>
</tr>
<tr>
<td>$request_time</td>
<td>处理客户端请求使用的时间 (1.3.9, 1.2.6); 从读取客户端的第一个字节开始计时。</td>
</tr>
<tr>
<td>$request_uri</td>
<td>这个变量等于包含一些客户端请求参数的原始URI，它无法修改，请查看$uri更改或重写URI，不包含主机名，例如：”/cnphp/test.php?arg=freemouse”。</td>
</tr>
<tr>
<td>$scheme</td>
<td>请求使用的Web协议, “http” 或 “https”</td>
</tr>
<tr>
<td>$sent_http_name</td>
<td>可以设置任意http响应头字段； 变量名中的后半部分“name”可以替换成任意响应头字段，如需要设置响应头Content-length，那么将“－”替换为下划线，大写字母替换为小写，形如：$sent_http_content_length 4096即可。</td>
</tr>
<tr>
<td>$server_addr</td>
<td>服务器端地址，需要注意的是：为了避免访问linux系统内核，应将ip地址提前设置在配置文件中。</td>
</tr>
<tr>
<td>$server_name</td>
<td>服务器名，<a target="_blank" rel="noopener" href="http://www.nginx.org/">www.nginx.org</a></td>
</tr>
<tr>
<td>$server_port</td>
<td>port of the server which accepted a request</td>
</tr>
<tr>
<td>$server_protocol</td>
<td>服务器的HTTP版本, 通常为 “HTTP/1.0” 或 “HTTP/1.1” , “HTTP/2.0”</td>
</tr>
<tr>
<td>$status</td>
<td>HTTP响应代码 (1.3.2, 1.2.2)</td>
</tr>
<tr>
<td>$tcpinfo_rtt、$tcpinfo_rttvar、$tcpinfo_snd_cwnd、$tcpinfo_rcv_space</td>
<td>客户端TCP连接的具体信息</td>
</tr>
<tr>
<td>$time_iso8601</td>
<td>服务器时间的ISO 8610格式 (1.3.12, 1.2.7)</td>
</tr>
<tr>
<td>$time_local</td>
<td>服务器时间（LOG Format 格式） (1.3.12, 1.2.7)</td>
</tr>
<tr>
<td>$uri</td>
<td>请求中的当前URI(不带请求参数，参数位于$args)，可以不同于浏览器传递的$request_uri的值，它可以通过内部重定向，或者使用index指令进行修改，$uri不包含主机名，如”/foo/bar.html”。</td>
</tr>
</tbody></table>
<h1 id="运算符"><a href="#运算符" class="headerlink" title="运算符"></a>运算符</h1><p>nginx if 不允许嵌套，变量与括号之间都需要有空格，否则nginx认为是一条命令</p>
<table>
<thead>
<tr>
<th>符号</th>
<th>注释</th>
</tr>
</thead>
<tbody><tr>
<td>=</td>
<td>比较运算符,并非 “==”</td>
</tr>
<tr>
<td>&amp;&amp;</td>
<td>逻辑与</td>
</tr>
<tr>
<td>or</td>
<td>逻辑或</td>
</tr>
</tbody></table>
<h1 id="模块"><a href="#模块" class="headerlink" title="模块"></a>模块</h1><p>nginx 将每个功能都分成不同的模块加载，具有很强的扩展性，与php的ext一样。<br>下面列出的都是常用到的模块和内置的模块</p>
<table>
<thead>
<tr>
<th>模块名</th>
<th>注释</th>
</tr>
</thead>
<tbody><tr>
<td>ngx_http_core_module</td>
<td>nginx核心模块,例如location, error_page和内置变量等等</td>
</tr>
<tr>
<td>ngx_http_access_module</td>
<td>允许/限制客户端的访问</td>
</tr>
<tr>
<td>ngx_http_fastcgi_module</td>
<td>这个不多说，如果你是PHP程序员一定知道</td>
</tr>
<tr>
<td>ngx_http_grpc_module</td>
<td>将请求发送到grpc服务器</td>
</tr>
<tr>
<td>ngx_http_gzip_module</td>
<td>压缩技术</td>
</tr>
<tr>
<td>ngx_http_proxy_module</td>
<td>反向代理的模块</td>
</tr>
<tr>
<td>ngx_http_log_module</td>
<td>日志的模块</td>
</tr>
<tr>
<td>ngx_http_rewrite_module</td>
<td>重写的模块</td>
</tr>
<tr>
<td>ngx_http_ssl_module</td>
<td>配置https的模块</td>
</tr>
</tbody></table>
<h1 id="命令行"><a href="#命令行" class="headerlink" title="命令行"></a>命令行</h1><p>nginx支持以下命令行参数</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>注释</th>
</tr>
</thead>
<tbody><tr>
<td>-? -h</td>
<td>打开帮助信息</td>
</tr>
<tr>
<td>-c file</td>
<td>使用指定配置文件启动nginx.</td>
</tr>
<tr>
<td>-g directives</td>
<td>设置配置文件外的全局指令</td>
</tr>
<tr>
<td>-p prefix</td>
<td>设置前缀路径（默认是：/usr/local/Cellar/nginx）</td>
</tr>
<tr>
<td>-q suppress</td>
<td>在检测配置文件期间屏蔽非错误信息</td>
</tr>
<tr>
<td>-s signal</td>
<td>给一个 nginx 主进程发送信号：stop（停止）, quit（退出）, reopen（重启）, reload（重新加载配置文件）</td>
</tr>
<tr>
<td>stop</td>
<td>立刻停止nginx运行</td>
</tr>
<tr>
<td>quit</td>
<td>优雅的关闭nginx</td>
</tr>
<tr>
<td>reload</td>
<td>重启</td>
</tr>
<tr>
<td>reopen</td>
<td>打开日志文件</td>
</tr>
<tr>
<td>-t</td>
<td>检测配置文件是否有语法错误，然后退出</td>
</tr>
<tr>
<td>-T</td>
<td>与-t相同</td>
</tr>
<tr>
<td>-v</td>
<td>显示版本信息并退出</td>
</tr>
<tr>
<td>-V</td>
<td>显示版本和配置选项信息，然后退出</td>
</tr>
</tbody></table>
<h1 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h1><h2 id="配置SSL"><a href="#配置SSL" class="headerlink" title="配置SSL"></a>配置SSL</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs bash">server &#123;<br>    listen 443;<br>    server_name nginx.org;<br>    ssl on;<br>    root /var/www/nginx.org;<br>    index index.html index.htm;<br>    ssl_certificate  cert/nginx.pem;<br>    ssl_certificate_key cert/nginx.key;<br>    ssl_session_timeout 5m;<br>    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;<br>    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;<br>    ssl_prefer_server_ciphers on;<br>    location / &#123;<br>        index index.html index.htm;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>
<h2 id="配置反向代理"><a href="#配置反向代理" class="headerlink" title="配置反向代理"></a>配置反向代理</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs bash">server &#123;<br>    listen 80;<br>    server_name  www.baidu.cim;<br> <br>    access_log  logs/nginx.access.log  main;<br>    error_log  logs/nginx.error.log;<br>    root   html;<br>    index  index.html index.htm index.php;<br><br>    location / &#123;<br>        proxy_pass  http://nginx.org;<br> <br>        proxy_redirect     off;<br>        proxy_set_header   Host             <span class="hljs-variable">$host</span>;<br>        proxy_set_header   X-Real-IP        <span class="hljs-variable">$remote_addr</span>;<br>        proxy_set_header   X-Forwarded-For  <span class="hljs-variable">$proxy_add_x_forwarded_for</span>;<br>        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;<br>        proxy_max_temp_file_size 0;<br>   &#125;<br>&#125;<br></code></pre></td></tr></table></figure>
<h2 id="配置负载均衡"><a href="#配置负载均衡" class="headerlink" title="配置负载均衡"></a>配置负载均衡</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs bash">upstream server &#123;  <br>    server 127.0.0.1:8080 weight=3;  <br>    server 127.1.1.1:8081;  <br>&#125;   <br><br>server &#123;<br>    listen 80;<br>    server_name  www.baidu.cim;<br> <br>    access_log  logs/nginx.access.log  main;<br>    error_log  logs/nginx.error.log;<br>    root   html;<br>    index  index.html index.htm index.php;<br><br>    location / &#123;<br>        proxy_pass  http://server;<br> <br>        proxy_redirect     off;<br>        proxy_set_header   Host             <span class="hljs-variable">$host</span>;<br>        proxy_set_header   X-Real-IP        <span class="hljs-variable">$remote_addr</span>;<br>        proxy_set_header   X-Forwarded-For  <span class="hljs-variable">$proxy_add_x_forwarded_for</span>;<br>        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;<br>        proxy_max_temp_file_size 0;<br>   &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>原文链接:<br><a target="_blank" rel="noopener" href="https://segmentfault.com/a/1190000015842717">NGINX宏观手记</a></p>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/Nginx/">Nginx</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Nginx/">Nginx</a>
                    
                      <a class="hover-with-bg" href="/tags/%E8%BF%90%E7%BB%B4/">运维</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2018/10/31/php/PHP%E6%89%8B%E5%86%8C-%E9%A2%84%E5%AE%9A%E4%B9%89%E6%8E%A5%E5%8F%A3/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">PHP手册-预定义接口</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2018/10/29/php/%E4%B8%80%E9%81%93%E7%9C%8B%E4%BC%BC%E7%AE%80%E5%8D%95%E7%9A%84%E9%9D%A2%E8%AF%95%E9%A2%98/">
                        <span class="hidden-mobile">【转】一道看似简单的面试题</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
        typing(title);
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
